Skip to content

feat: 打印/导出时只保留题目配图,不包含拍照原图 / exclude photo imports from print & export, keep question figures only - #46

Open
1288893 wants to merge 3 commits into
margrop:mainfrom
1288893:feat/print-export-figure-only-v2
Open

1288893 wants to merge 3 commits into
margrop:mainfrom
1288893:feat/print-export-figure-only-v2

Conversation

@1288893

@1288893 1288893 commented Nov 26, 2026

Copy link
Copy Markdown

问题描述 / Problem

打印预览和导出 Word 时,会把用户拍照导入的原始照片(originalImageUrl)一并输出,
导致打印内容冗余、浪费纸张。学生整理错题本时,只需要题目自带的配图,不需要原始拍照。

When printing or exporting to Word, the app includes the original photo imported
by the user (originalImageUrl), which is redundant and wastes paper/space.
Students only need the clean typeset question with its embedded diagram — not the raw photo.


改动说明 / Changes

打印预览 / Print Preview (/print-preview)

  • 移除了「无配图时回退显示拍照原图」的逻辑
  • 现在只渲染 figureImage / figureSvg(题目自带配图)
  • Removed fallback to originalImageUrl when no structured figure exists
  • Now only renders figureImage / figureSvg (question-embedded figures)

Word 导出 / Word Export (.docx)

  • 新增 includeFigures 选项(默认开启),用于嵌入题目配图
  • includeImages(拍照原图)默认改为关闭
  • 导出对话框新增两个独立勾选框
  • Added includeFigures option (default: true) to embed question figures
  • includeImages (original photo) now defaults to false
  • UI shows two separate checkboxes in the export dialog

国际化 / i18n

  • zh.ts 和 en.ts 新增 includeFigures 相关文案
  • Updated zh.ts and en.ts with new keys for includeFigures

测试 / Tests

  • 更新了 printable-question、from-error-item、to-docx 的单元测试
  • lint、单元测试、集成测试全部通过 ✅
  • Updated unit tests for printable-question, from-error-item, to-docx
  • All lint, unit, and integration tests pass ✅

@1288893
1288893 requested a review from margrop as a code owner November 26, 2026 05:46

@margrop margrop left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感谢贡献!打印/导出只保留题目配图、备份导入预检以及 Windows 路径修复都是很实用的改进。

不过当前分支里混入了多个相互独立的改动,且部分代码存在需要修复的问题,建议先调整后再合入:

1. 请按功能拆分 PR

当前 PR 标题和说明对应的是第一个提交(006c77c3,打印/导出配图),但后续又推送了 5 个与该主题无关的提交。建议本 PR 只保留打印/导出配图相关改动,其余有价值的改动单独开 PR,便于逐个审查和合入。


2. 本 PR(打印/导出配图,006c77c3)需确认的点

整体实现和单测写得比较清晰,有以下三点希望确认:

  • 默认打印模式变更:src/lib/print/print-preview-options.ts 将 DEFAULT_PRINT_OPTIONS.showQuestionText 从 false 改为了 true,这会改变新用户首次打印预览的默认模式(原图 → 文字),但 PR 描述未提及,请确认是否必要并在说明中写明。
  • 历史带图题目的配图兜底:src/components/print-preview/printable-question.tsx 直接移除了无配图时回退显示 originalImage 的逻辑。对于历史上拍照导入、hasFigure === true 但尚未生成 figureSvg 或裁剪 figureImage 的老题目,文字模式下会出现“如图所示”却没有图的情况,建议评估是否需要保留针对 hasFigure 的兜底或提示。
  • JSON 导出行为一致性:src/components/error-list/export-questions-dialog.tsx 在非 Word 格式时传了 includeFigures: false,但 fromErrorItem 仍无条件导出 figureSvg,且 parse.ts/schema.ts 已支持 figureImage/figureSource。建议明确 JSON 导出是否需要同步支持或注明差异。

3. 其余提交的建议(拆分 PR 时参考)

  • 58f6c513(scripts/copy-pdfjs-assets.mjs Windows 路径修复):改动干净且有价值,欢迎直接拆成独立 fix PR。
  • b35c0a0a(备份「导入全部」缺用户预检):很实用,欢迎拆成独立 fix PR,建议同时在 src/__tests__/integration/data-backup.test.ts 补充对应测试用例。
  • 6d2dc9b4(练习列表着色/筛选 + 错题卡片进度):拆分提 PR 前建议完善以下细节并补充测试:
    1. src/app/api/practice/questions/route.ts 中 findIdsByLastResult 只匹配 r.result = ${result},未兼容历史记录中 result 为 NULL 仅存 isCorrect 的情况(前端 practice-history.tsx 已兼容);另外 not_attempted 在卡片上归为黄色,但筛选「作错」时不包含,语义不太一致;全量取 ID 再拼 id: { in: lastResultIds } 在数据量较大时也存在 SQLite 参数数量上限风险。
    2. src/app/api/error-items/list/route.ts 中 loadPracticeStats 建议排除 source: 'duplicate_import'(参考 weak-tags 接口),并确认 not_attempted 是否应计入作答总数 total。
    3. src/components/error-list/error-item-card.tsx 对未练习过的题目也常驻显示 4 个红色 0/0,视觉上较刺眼,建议未练习时使用中性色或按需展示。
  • 20991301 / 738caeeb(LINUX.md / install.sh / start.sh):仓库已有 packaging/ 和 doc/ 维护安装包与部署文档,不建议在根目录新增这套脚本;此外脚本本身存在几处必现问题,建议直接移除:
    1. start.sh 使用 : "${PORT:-3000}" / : "${HOST:-0.0.0.0}"(:- 只展开不赋值,应为 :=),在 set -u 下未传环境变量时会直接报 unbound variable 退出。
    2. install.sh 编译产物在 dist-scripts/scripts/*.js,但 start.sh 调用的是 dist-scripts/*.js(少了 scripts/ 层级),且因 || true 被静默忽略。
    3. install.sh 文档写的是大写 NPM_REGISTRY,但脚本内读取的是小写 ${npm_registry:-...},环境变量不会生效。
    4. install.sh 将 NEXTAUTH_SECRET 写入 .env,而 start.sh 读写 .nextauth_secret 并导出覆盖,两处不一致。

清理分支并调整后,欢迎再 @ 我复审!

- 打印:历史题目标记了 hasFigure 但尚未生成 SVG/裁剪配图时,
  文字模式回退显示拍照原图,避免「如图所示」却没有图
- 导出:includeFigures 同时控制 figureSvg / figureImage / figureSource,
  开关与导出内容一致;JSON 作为数据交换格式始终保留题目配图
@1288893
1288893 force-pushed the feat/print-export-figure-only-v2 branch from 738caee to 81d61f3 Compare November 28, 2026 12:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants